fix: openrouter in providers and modellist length is greater than 0#766
fix: openrouter in providers and modellist length is greater than 0#766yinwm merged 3 commits intosipeed:mainfrom
Conversation
penzhan8451
left a comment
There was a problem hiding this comment.
In the case of openrouter is in providers and modellist is not empty && modellist does not contain openrouter config, an error will be returned and the process will quit.
| providerModels := config.ConvertProvidersToModelList(cfg) | ||
| existingModelNames := make(map[string]bool) | ||
| for _, m := range cfg.ModelList { | ||
| existingModelNames[m.ModelName] = true | ||
| } | ||
| for _, pm := range providerModels { | ||
| if !existingModelNames[pm.ModelName] { | ||
| cfg.ModelList = append(cfg.ModelList, pm) | ||
| } | ||
| } |
There was a problem hiding this comment.
| providerModels := config.ConvertProvidersToModelList(cfg) | |
| existingModelNames := make(map[string]bool) | |
| for _, m := range cfg.ModelList { | |
| existingModelNames[m.ModelName] = true | |
| } | |
| for _, pm := range providerModels { | |
| if !existingModelNames[pm.ModelName] { | |
| cfg.ModelList = append(cfg.ModelList, pm) | |
| } | |
| } | |
| providerModels := config.ConvertProvidersToModelList(cfg) | |
| existing := make(map[string]struct{}, len(cfg.ModelList)+len(providerModels)) | |
| for _, m := range cfg.ModelList { | |
| existing[m.ModelName] = struct{}{} | |
| } | |
| var toAdd []Model | |
| for _, pm := range providerModels { | |
| if _, ok := existing[pm.ModelName]; !ok { | |
| toAdd = append(toAdd, pm) | |
| existing[pm.ModelName] = struct{}{} | |
| } | |
| } | |
| cfg.ModelList = append(cfg.ModelList, toAdd...) |
nikolasdehor
left a comment
There was a problem hiding this comment.
Good bug fix. The problem is clear: when a user has both model_list entries and providers config, the old code skipped ConvertProvidersToModelList entirely if model_list was non-empty, meaning provider-sourced models (like OpenRouter) were silently dropped.
The fix correctly merges by deduplicating on ModelName. One edge case worth noting:
- Name collision with different config: If a model in
model_listand a provider have the sameModelNamebut different API keys or base URLs, the explicitmodel_listentry wins (it is kept, the provider entry is skipped). This seems like the right precedence but may be worth documenting.
Otherwise clean and minimal. LGTM.
|
@penzhan8451 Good fix on the OpenRouter provider initialization. When model_list has entries but no OpenRouter config, skipping the providers block entirely would cause unexpected errors. Thanks for catching that edge case. We have a PicoClaw Dev Group on Discord where contributors share ideas and collaborate. If you're interested, send an email to |
📝 Description
🗣️ Type of Change
🤖 AI Code Generation
🔗 Related Issue
📚 Technical Context (Skip for Docs)
Reference URL:
Reasoning:
/////////////
when user setup both:
this will skip providers configuration,and will return with err
/////////////
🧪 Test Environment
📸 Evidence (Optional)
Details
when user setup both:
this will skip providers configuration,and will return with err
Click to view Logs/Screenshots
☑️ Checklist